package com.byzk.p2p.admin.system.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.JsonMsg;
import com.byzk.p2p.admin.system.dto.Page;
import com.byzk.p2p.admin.system.service.PageService;

@Controller
@RequestMapping("/admin/page")
public class PageController extends AdminBaseController {

	@Autowired
	private PageService pageService;
	
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public String listPage(Model model){
		List<Page> pageList=pageService.listAll();
		model.addAttribute("pageList", pageList);
		return ftl(Thread.currentThread().getStackTrace()); 
	}
	
	@RequestMapping(value="/update",method=RequestMethod.GET)
	public String updatePage(Model model,@RequestParam("id") Integer id){
		Page page=pageService.getById(id);
		model.addAttribute("page", page);
		return ftl(Thread.currentThread().getStackTrace()); 
	}
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	@ResponseBody
	public String savePage(@RequestBody Page page){
		try {
			pageService.saveOrUpdate(page);
			super.printJSON(new JsonMsg(-1, "操作成功"));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String addPage(Model model){
		return ftl(Thread.currentThread().getStackTrace()); 
	}
}
